<?php

namespace App;

use DB;
use QrCode;
use Carbon\Carbon;

/**
 * Class Datatables
 * @package App
 */
class Datatables
{

    /**
     * 帖子列表
     * @return array
     */
    static function PostingsList()
    {
        $orderDir = $_POST['order'][0]['dir'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $title = request()->columns[0]['search']['value'];
        $user_name = request()->columns[1]['search']['value'];
        $time = request()->columns[2]['search']['value'];
        $status = request()->columns[3]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量

        $result = DB::table('tbl_archive')->select('archive_id', 'keshi', 'city', 'title', 'member_id', 'pub_time', 'is_hot', 'is_view', 'view_time', 'hot_time');//->where('is_view', Postings::VIEW_YES);//->orWhere('view_time', '!=', null);
        $return['recordsTotal'] = $result->count();
        if ($status == 1) {
            $result->where('is_view', Postings::VIEW_YES);
        } else if ($status == 2) {
            $result->where('view_time', '>=', date('Y-m-d H:i:s', time()));
        } else if ($status == 3) {
            $result->where('pub_time', '<=', date('Y-m-d H:i:s', time()))->where('is_view', Postings::VIEW_NO);
        }
        if ($title) {
            $result->where('title', 'like', '%' . $title . '%');
        }
        if ($user_name) {
            $user_id = DB::table('t_member')->where('name', $user_name)->value('c_id');
            $result->where('member_id', $user_id);
        }
        if (!$time) {
            $date = ['2018-01-01 00:00:00', '2029-01-01 00:00:00'];
        } else {
            $date = date2Date($time);
        }
        $result->where('pub_time', '>=', $date[0])->where('pub_time', '<=', $date[1]);
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("archive_id", $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                if ($data->is_hot === Postings::HOT_YES || $data->hot_time) {
                    $set = "<span class='btn-hot$data->archive_id'><button class='btn btn-success btn-qjj' data-id='$data->archive_id' >取消加精</button></span>";
                    $jj = "加精时间：" . $data->hot_time;
                } else {
                    $set = "<button  class='btn btn-info'  onclick='hot(" . $data->archive_id . ")' data-toggle='modal' data-target='#btn-hot' >加精</button>";
//                    $set = "<span class='btn-hot$data->archive_id'><button class='btn btn-success btn-jj' data-id='$data->archive_id' >加精</button></span>";
                    $jj = Postings::$HotDisplay[$data->is_hot];
                }
                $aset = '';
                if ($data->is_view === Postings::VIEW_NO) {
                    $c_time = '已删除';
                } else {
                    $c_time = $data->pub_time;
                    $aset = "<button  class='btn btn-danger'  onclick='del(" . $data->archive_id . ")' data-toggle='modal' data-target='#btn-del' >删除</button>";
                }
                if ($data->view_time && $data->view_time !== '1' && strtotime($data->view_time) >= $time) {
                    $aset = "<button class='btn btn-danger btn-cancle' data-id='$data->archive_id' >撤销</button>";
                    $c_time = $data->view_time;
                }
                $return['data'][] = [
                    "<input type='checkbox' class='check' id='check$data->archive_id' data-id='$data->archive_id'>",
                    $data->archive_id,
                    $data->keshi,
                    $data->city,
                    $data->title,
                    "<p class='hot$data->archive_id'>" . $jj . "</p>",
                    DB::table('t_member')->where('c_id', $data->member_id)->value('name'),
                    $c_time,
                    "<a class='btn' href='/posting/edit/$data->archive_id' >修改</a>
                        <button class='btn btn-info btn-post' data-id='$data->archive_id' >回帖</button>
                        $aset
                        $set"
                ];
            }
        }
        return $return;
    }


    /**
     * 商铺列表
     * @return array
     */
    static function ShopList()
    {
        $orderText = [
            0 => 'id',
            2 => 'lat',
            3 => 'lng',
        ];
        $orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $shop_name = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('s_shanghu')->select('id', 'store_name', 'lat', 'lng', 'url', 'introduce');
        $return['recordsTotal'] = $result->count();
        if ($shop_name) {
            $result->where('store_name', 'like', '%' . $shop_name . '%');
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        $order = $orderColumn ? $orderText[$orderColumn] : 'id';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<a class='btn btn-info' data-id='$data->id' href='/discovery/shopModify/$data->id'>修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>";
                $return['data'][] = [
                    $data->id,
                    $data->store_name,
                    $data->lat,
                    $data->lng,
//                    "<a href='" . $data->pic_s . "' data-effect='mfp-zoom-in' ><img src='" . $data->pic_s . "' class='img-responsive' /></a>",
//                    "<a href='" . $data->pic1 . "' data-effect='mfp-zoom-in' ><img src='" . $data->pic1 . "' class='img-responsive' /></a>",
                    $data->url,
                    mb_substr($data->introduce, 0, 10, 'utf-8') . '...',
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 商品列表
     * @return array
     */
    static function CommoditiesList()
    {
        $orderDir = $_POST['order'][0]['dir'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $title = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('s_shangpin')->select('id', 'title', 'store_name', 'is_cuxiao', 'stock_num', 'ctime', 'is_hot', 'xian_price');
        $return['recordsTotal'] = $result->count();
        if ($title) {
            $result->where('title', 'like', '%' . $title . '%');
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy('id', $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<div class='btn-group dropdown m-r-10'>
                                 <button aria-expanded='xfalse' data-toggle='dropdown' class='btn btn-danger dropdown-toggle waves-effect waves-light'
                                       type='button' data-id='1'>操作 <span class='caret'></span></button>
                                 <ul role='menu' class='dropdown-menu animated flipInY'>
                                 <li><a  href='/commodity/commodityModify/$data->id' data-id='" . $data->id . "'>编辑商品</a></li>
                                 <li><span  href='#' class='btn-del'  data-id='" . $data->id . "'>删除商品</span></li>
                                 </ul>
                             </div>";
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $data->store_name,
                    Commodity::$CuxiaoDisplay[$data->is_cuxiao],
                    Commodity::$HotDisplay[$data->is_hot],
                    $data->stock_num,
                    $data->xian_price,
                    $data->ctime,
                    $set
                ];
            }
        }
        return $return;
    }


    //角色列表

    /**
     * @return array
     */
    static function RolesList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = Role::select('id', 'name', 'display_name', 'description');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", "asc")->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<span class='btn btn-success' onclick='edit(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >编辑</span>";
                $return['data'][] = [$data->name, $data->display_name, $data->description, $set];
            }
        }

        return $return;
    }


    //权限列表

    /**
     * @return array
     */
    static function Permissionslist()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = Permission::select();
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", "asc")->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<li><span onclick='edit(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >编辑</span></li>
                                <li class='divider'></li><li><span href='#' class='btn-del' data-id='" . $data->id . "'>删除</span></li>";
                $set = "<div class='btn-group dropdown m-r-10'>
                                 <button aria-expanded='false' data-toggle='dropdown' class='btn btn-danger dropdown-toggle waves-effect waves-light'
                                       type='button' data-id='1'>操作 <span class='caret'></span></button>
                                 <ul role='menu' class='dropdown-menu animated flipInY'>" . $set . "</ul>
                             </div>";
                $return['data'][] = [
                    $data->name,
                    $data->display_name,
                    $data->pid == 0 ? '超级管理' : Permission::findOrFail($data->pid)->display_name,
                    Permission::$StatusDisplay[$data->status],
                    $data->pid == 0 ? '不能修改' : $set
                ];
            }
        }

        return $return;
    }


    /**
     * 活动列表
     * @return array
     */
    static function ActivityList()
    {
        $orderDir = $_POST['order'][0]['dir'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('s_activity')->select('id', 'aname', 'type', 'introduce', 'start_time', 'end_time');
        $return['recordsTotal'] = $result->count();
        if ($name) {
            $result->where('aname', $name);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy('id', $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<div class='btn-group dropdown m-r-10'>
                                 <button aria-expanded='xfalse' data-toggle='dropdown' class='btn btn-danger dropdown-toggle waves-effect waves-light'
                                       type='button' data-id='1'>操作 <span class='caret'></span></button>
                                 <ul role='menu' class='dropdown-menu animated flipInY'>
                                 <li><a  href='/activity/activityModify/$data->id' data-id='" . $data->id . "'>编辑活动</a></li>
                                 <li><span  href='#' class='btn-del'  data-id='" . $data->id . "'>删除活动</span></li>
                                 </ul>
                             </div>";
                $return['data'][] = [
                    $data->id,
                    $data->aname,
                    Activity::$TypeDisplay[$data->type],
                    mb_substr($data->introduce, 0, 10, 'utf-8') . '...',
                    $data->start_time,
                    $data->end_time,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 团购列表
     * @return array
     */
    static function PromotionList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $id = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据

        #2.1找出有促销活动的商品
        $commodties_ids = DB::table('s_order')
            ->where('act_type', '!=', Promotion::ACT_TYPE_NULL)
            ->where('type', Promotion::STATUS_ON)
            ->pluck('sp_id')->toArray();
        $result = DB::table('s_shangpin')
            ->select('id', 'title', 'xian_price', 'cx_type')
            ->whereIn('id', $commodties_ids)
            ->where('is_cuxiao', Commodity::CUXIAO_ON);
        $return['recordsTotal'] = $result->count();
        if ($id) {
            $result->where('id', $id);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-send' data-id='$data->id' >去发货</button>";
                //待发货数量
                if (intval($data->cx_type) === Commodity::CUXIAO_TYPE_ROB) {
                    $count = DB::table('s_order')
                        ->where('sp_id', $data->id)
                        ->where('is_win', Promotion::IS_WIN_YES)
                        ->where('act_type', Promotion::ACT_TYPE_ROB)
                        ->where('type', Promotion::STATUS_ON)
                        ->count();
                } else if (intval($data->cx_type) === Commodity::CUXIAO_TYPE_COLLAGE) {
                    $count = DB::table('s_order')
                        ->where('sp_id', $data->id)
                        ->where('act_type', Promotion::ACT_TYPE_COLLAGE)
                        ->where('type', Promotion::STATUS_ON)
                        ->count();
                } else {
                    $count = 0;
                }
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $data->xian_price,
                    $count,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 团购发货列表
     * @param $commodity_id
     * @return array
     */
    static function promotionSendList($commodity_id)
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $id = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据

        #2.1找出有促销活动的商品
        $result = DB::table('s_order')
            ->select('id', 'order_num', 'username', 'sp_num', 'phone', 'act_type', 'sheng', 'shi', 'xian', 'detail', 'delivery', 'express_name', 'express_order')
            ->where('sp_id', $commodity_id)
            ->where('type', Promotion::STATUS_ON);
        $act_type = DB::table('s_shangpin')->where('id', $commodity_id)->value('cx_type');
        if (intval($act_type) === Activity::TYPE_COLLAGE) {

            $result = $result->where('act_type', Activity::TYPE_COLLAGE);
        } else {
            $result = $result->where('is_win', Promotion::IS_WIN_YES)
                ->where('act_type', Activity::TYPE_ROB);
        }

        $return['recordsTotal'] = $result->count();
        if ($id) {
            $result->where('id', $id);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                if ($data->delivery === Promotion::DELIVERY_NULL) {
                    $content = '';
                    $set = "<button class='btn btn-info btn-manual' data-id='$data->id' >人工配送</button>
                        <button class='btn btn-info btn-express' onclick='edit(" . $data->id . ")'  data-toggle='modal' data-target='#express'>快递发货</button>";
                } else {
                    $content = Promotion::$DeliveryDisplay[$data->delivery] . $data->express_name . '：' . $data->express_order;
                    $set = "";
                }

                //待发货数量
                $return['data'][] = [
                    $data->id,
                    $data->order_num,
                    $data->username,
                    $data->phone,
                    $data->sp_num,
                    Promotion::$ACTTypeDisplay[$data->act_type],
                    $data->sheng . $data->shi . $data->xian . $data->detail,
                    $content,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 订单管理
     * @return array
     */
    static function OrderList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $order_num = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据

        #2.1找出有促销活动的商品
        $result = DB::table('s_order')
            ->select('id', 'order_num', 'username', 'phone', 'sp_num', 'act_type', 'sheng', 'shi', 'xian', 'detail', 'delivery', 'express_name', 'express_order')
            ->where('act_type', Promotion::ACT_TYPE_NULL)
            ->where('type', Promotion::STATUS_RECEIVING);

        $return['recordsTotal'] = $result->count();
        if ($order_num) {
            $result->where('order_num', $order_num);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                if ($data->delivery === Promotion::DELIVERY_NULL) {
                    $content = '';
                    $set = "<button class='btn btn-info btn-manual' data-id='$data->id' >人工配送</button>
                        <button class='btn btn-info btn-express' onclick='edit(" . $data->id . ")'  data-toggle='modal' data-target='#express'>快递发货</button>";
                } else {
                    $content = Promotion::$DeliveryDisplay[$data->delivery] . $data->express_name . '：' . $data->express_order;
                    $set = "";
                }

                //待发货数量
                $return['data'][] = [
                    $data->id,
                    $data->order_num,
                    $data->username,
                    $data->phone,
                    $data->sp_num,
                    Promotion::$ACTTypeDisplay[$data->act_type],
                    $data->sheng . $data->shi . $data->xian . $data->detail,
                    $content,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 提现列表
     * @return array
     */
    static function operationRecordList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $id = request()->columns[0]['search']['value'];
        $mobile = request()->columns[1]['search']['value'];
        $type = request()->columns[2]['search']['value'];
		$time = request()->columns[3]['search']['value'];
        //每页显示数量
        $pageNum = request('length', 50);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = OperationRecord::select('id', 'cash', 'number', 'status', 'user_id', 'create_time','tixian_time', 'reflect_type', 'alipay_account', 'content', 'commodity_number')
            ->where('type', OperationRecord::TYPE_WITHDRAW)
            ->where('reflect_type', '!=', OperationRecord::REFLECT_TYPE_EXCHANGE);
        $return['recordsTotal'] = $result->count();
        if ($id) {
            $result->where('id', $id);
        }
        if ($mobile) {
            $user_id = DB::table('t_member')->where('phone', $mobile)->value('c_id');
            $result->where('user_id', $user_id);
        }
        if (is_numeric($type)) {
            if ($type == 1) {
                $result->where('reflect_type', OperationRecord::REFLECT_TYPE_REAL);
            } else if ($type == 2) {
                $result->where('reflect_type', OperationRecord::REFLECT_TYPE_WECHAT);
            } else {
                $result->whereNotIn('reflect_type', [OperationRecord::REFLECT_TYPE_REAL, OperationRecord::REFLECT_TYPE_WECHAT]);
            }
        }
		
        if (!$time) {
            $times = ['2018-01-01 00:00:00', '2029-01-01 00:00:00'];
        } else {
            $times = date2Date($time);
        }
		
		$result->where('create_time', '>', $times[0])->where('create_time', '<', $times[1]);
			
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();
		
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = '';
                if ($data->status === OperationRecord::STATUS_WAITING) {
                    if ($data->reflect_type === OperationRecord::REFLECT_TYPE_REAL) {
                        $set = "<button  class='btn btn-info'  onclick='agree(" . $data->id . ")' data-toggle='modal' data-target='#agree' >通过</button>";
                        $number = 1;
                        $content = $data->content . $data->commodity_number;
                    } else {
                        $number = $data->cash;
                        $set = "<button class='btn btn-info btn-on' data-id='$data->id' >通过</button>";
                        $content = '';
                    }
                    $set .= "<button  class='btn btn-info'  onclick='refuse(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >拒绝</button>";
                } else {
                    if ($data->reflect_type === OperationRecord::REFLECT_TYPE_REAL) {
                        $number = 1;
                        $content = $data->content . $data->commodity_number;
                        $set = "<button  class='btn btn-info'  onclick='check(" . $data->id . ")' data-toggle='modal' data-target='#check' >查看</button>";
                    } else {
                        $number = $data->cash;
                        $content = '';
                    }
                }

                $user = DB::table('t_member')->select('name', 'phone', 'alipay')->where('c_id', $data->user_id)->first();
                $return['data'][] = [
                    "<input type='checkbox' class='check' id='check$data->archive_id' data-id='$data->id'>",
                    $data->id,
                    $user->name,
                    $user->phone,
                    $data->alipay_account,
                    OperationRecord::$ReflectTypeDisplay[$data->reflect_type],
                    $number,
                    $content,
                    "<p class='status$data->id'>" . OperationRecord::$StatusDisplay[$data->status] . "</p>",
                    $data->create_time,
					$data->tixian_time,
                    "<div class='set$data->id'>" . $set . "</div>"
                ];
            }
        }
        return $return;
    }
	
	//每日体现总金额列表
	static function tixiantongji(){
		$return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //$name = request()->columns[0]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('operation_record')->select(DB::raw('sum(cash) as heji,date_format(tixian_time,"%Y-%m-%d") as times'))->groupBy(DB::raw("date_format(tixian_time,'%Y-%m-%d')"))
		->where('type', OperationRecord::TYPE_WITHDRAW)
		->where('tixian_time','!=',null)
        ->where('reflect_type', '!=', OperationRecord::REFLECT_TYPE_EXCHANGE);
		//if ($name) {
		//	$id = User::where('name', 'like' ,'%'.$name.'%')->where('sign', 1)->value('c_id');
        //    $result->where('user_id', $id);
       // }
		//$result->where('status',1)->where('is_del',1);
		
        $return['recordsTotal'] = count($result->get());
        // 过滤后的总数量
        $return['recordsFiltered'] = count($result->get());
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
		
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy(DB::raw("date_format(tixian_time,'%Y-%m-%d')"), 'desc')->get();
        if (count($datas) > 0) {
			
            foreach ($datas as $data) {
				
                $return['data'][] = [
					$data->times,
					$data->heji
                ];
            }
        }
        return $return;		
	}


    /*
     * 积分商品
     */
    /**
     * @return array
     */
    static function IntegralCommodityList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = IntegralCommodity::select('id', 'title', 'cost_coin_number', 'recharge_amount', 'reflect_type')
            ->where('type', OperationRecord::TYPE_WITHDRAW);
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<a class='btn btn-info btn-on' href='/integral/detail/$data->id' >修改</a>
                        <button class='btn btn-info btn-del' data-id='$data->id' >删除</button>";
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $data->cost_coin_number,
                    $data->recharge_amount,
                    IntegralCommodity::$ReflectTypeDisplay[$data->reflect_type],
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * banner列表
     * @return array
     */
    static function BannerList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Banner::select('id', 'purl', 'type', 'sort');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/banner/bannerModify/$data->id' >修改</a>";
                $pic = "<img src='$data->purl' width='200px'/> ";
                $return['data'][] = [
                    $data->id,
                    $pic,
                    Banner::$TypeDisplay[$data->type],
                    $data->sort,
                    $set
                ];
            }
        }
        return $return;
    }

    /**
     * 科室列表
     * @return array
     */
    static function KeshiList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Keshi::select('id', 'title', 'ctime', 'weight', 'hot', 'pic');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/keshi/keshiModify/$data->id' >修改</a>";
                $pic = "<img src='$data->pic' width='50px'/> ";
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $data->weight,
                    $pic,
                    Keshi::$HotDisplay[$data->hot],
                    $data->ctime,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 商铺类型
     * @return array
     */
    static function ShopTypeList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = ShanghuType::select('id', 'store_type', 'weight', 'pic', 'act', 'pin_pic');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/discovery/shopTypeModify/$data->id' >修改</a>";
                $return['data'][] = [
                    $data->id,
                    $data->store_type,
                    $data->weight,
                    "<img src='$data->pic' width='50px'/> ",
                    "<img src='$data->act' width='50px'/> ",
                    "<img src='$data->pin_pic' width='50px'/> ",
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 话题
     * @return array
     */
    static function HuatiList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Huati::select('id', 'p_id', 'ctime', 'title', 'weight', 'hot');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/huati/huatiModify/$data->id' >修改</a>";
                $parent = HuatiParent::where('id', $data->p_id)->value('title');
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $parent ? $parent : '',
                    $data->weight,
                    Huati::$HotDisplay[$data->hot],
                    $data->ctime,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 父级话题
     * @return array
     */
    static function HuatipList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = HuatiParent::select('id', 'title', 'hot', 'weight');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/huatip/huatipModify/$data->id' >修改</a>";
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $data->weight,
                    HuatiParent::$HotDisplay[$data->hot],
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 商城banner
     * @return array
     */
    static function Banner2List()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Banner2::select('id', 'purl', 'linkurl', 'sort');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/banner2/bannerModify/$data->id' >修改</a>";
                $pic = "<img src='$data->purl' width='200px'/> ";
                $return['data'][] = [
                    $data->id,
                    $pic,
                    $data->linkurl,
                    $data->sort,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 圈主列表
     * @return array
     */
    static function HuatiOwner()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));

        $return['data'] = [];

        //数据
        $result = HuatiOwner::with('user:c_id,name,c_avatar');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        // 显示数量
        $datas = $result->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >撤销圈主</button>";
                foreach (HuatiOwner::$LevelDisplay as $key => $value) {
                    if ($data->level !== $key) {
                        $set .= " <button class='btn btn-success btn-level' data-id='$data->id' data-level='$key' >$value</button>";
                    }
                }
                $avatar = $data->user->c_avatar;
                $pic = "<img src='$avatar' width='80px'/> ";
                $return['data'][] = [
                    $data->id,
                    $data->user->name,
                    $pic,
                    $data->circle_name,
                    HuatiOwner::$LevelDisplay[$data->level],
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 用户列表
     * @return array
     */
    static function UserList()
    {
        $columns = [
            0 => 'c_id',
        ];
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $phone = request()->columns[1]['search']['value'];
        $status = request()->columns[2]['search']['value'];
        $sign = request()->columns[3]['search']['value'];
        $time = request()->columns[4]['search']['value'];
        $pageNum = request()->columns[5]['search']['value'];
        $column = request()->order[0]['column'];
        $dir = request()->order[0]['dir'];
        //每页显示数量
        $pageNum = $pageNum ? $pageNum : 10;//request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = User::select('c_id', 'name', 'c_avatar', 'phone', 'ban_status', 'sex', 'ban_time', 'create_time', 'qq', 'wechat');
        $return['recordsTotal'] = $result->count();
        if ($phone) {
            $result->where('phone', $phone);
        }
        if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }
        if ($status) {
            $result->where('ban_status', $status);
        }
        if ($sign) {
            $result->where('sign', $sign);
        }
        if ($time) {
            $time = date2Date($time);
            $result->where('create_time', '>', $time[0])->where('create_time', '<', $time[1]);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        //排序
        if (in_array($column, array_keys($columns))) {
            $result->orderBy($columns[$column], $dir);
        }
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                if ($data->ban_status === User::BANSTATUS_ON) {
                    $set = "<button  class='btn btn-info'  onclick='ban(" . $data->c_id . ")' data-toggle='modal' data-target='#exampleModal' >禁言</button>";
                    $status = User::$BanStatusDisplay[$data->ban_status];
                } else {
                    $set = "<button class='btn btn-info btn-on' data-id='$data->c_id'>解禁</button>";
                    $status = "解禁时间" . date("Y-m-d H:i:s", $data->ban_time);
                }
                if ($data->phone) {
                    $content = '手机号:' . $data->create_time;
                } else if ($data->qq) {
                    $content = 'qq:' . $data->create_time;
                } else {
                    $content = '微信:' . $data->create_time;
                }
                $return['data'][] = [
                    $data->c_id,
                    $data->name,
                    "<img src='" . $data->c_avatar . "'width='70px' class='img-responsive' />",
                    $data->phone,
                    $data->sex,
                    $content,
                    $status,
                    $set
                ];
            }
        }
        return $return;
    }

    /**
     * 举报列表
     * @return array
     */
    /*static function ReportList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $type = request()->columns[0]['search']['value'];
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Report::select('id', 'reportUserId', 'reportArticleId', 'text', 'ctime', 'type');
        $return['recordsTotal'] = $result->count();
        if (is_numeric($type)) {
            $result->where('type', $type);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $user_name = $data->reportUserId ? User::where('c_id', $data->reportUserId)->value('name') : '';
                $posting_title = $data->reportArticleId ? Postings::where('archive_id', $data->reportArticleId)->value('title') : '';
                $return['data'][] = [
                    $data->id,
                    $user_name,
                    $posting_title,
                    $data->text,
                    $data->ctime,
                    Report::$TypeDisplay[$data->type]
                ];
            }
        }
        return $return;
    }*/
	
    /**
     * 举报列表
     * @return array
     */
    static function ReportList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $type = request()->columns[0]['search']['value'];
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Report::select('id', 'article_id', 'report_type', 'accused_health_id', 'accused_user_id', 'user_id','content','create_time','type');
        $return['recordsTotal'] = $result->count();
        if (is_numeric($type)) {
            $result->where('type', $type);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $user_name = $data->user_id ? User::where('c_id', $data->user_id)->value('name') : '';
                //$posting_title = $data->reportArticleId ? Postings::where('archive_id', $data->reportArticleId)->value('title') : '';
				if($data->report_type==1 && $data->accused_user_id!=''){
					$jubaorc = User::where('c_id', $data->accused_user_id)->value('name');
				}else{
					$jubaorc ='';
				}
					
				if($data->report_type==2 && $data->article_id!=''){
					$jubaow = Carticle::where('id', $data->article_id)->value('content');
				}else{
					$jubaow ='';
				}
				
                $return['data'][] = [
                    $data->id,
                    $user_name,
                    $jubaorc,
					$jubaow,
                    $data->content,
                    $data->create_time,
                    Report::$TypeDisplay[$data->report_type]
                ];
            }
        }
        return $return;
    }

    /**
     * 用户轨迹
     * @return array
     */
    static function UserOperationList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $user_name = request()->columns[0]['search']['value'];
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = OperationRecord::select('id', 'number', 'name', 'status', 'type', 'reflect_type','user_id', 'create_time', 'cash');
        $return['recordsTotal'] = $result->count();
        if ($user_name) {
            $c_id = User::where('name', 'like', '%' . $user_name . '%')->pluck('c_id')->toArray();
            if (count($c_id) <= 0) {
                $result->where('user_id', $user_name);
            } else if (count($c_id) === 1) {
                $result->where('user_id', $c_id[0]);
            } else {
                $result->whereIn('user_id', $c_id);
            }
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $user_name = User::where('c_id', $data->user_id)->value('name');
                $return['data'][] = [
                    $data->id,
                    $user_name,
                    $data->name,
                    $data->type === OperationRecord::TYPE_WITHDRAW && ($data->reflect_type === OperationRecord::REFLECT_TYPE_ALIPAY || $data->reflect_type === OperationRecord::REFLECT_TYPE_WECHAT) ? '' : (is_numeric($data->number) ? '-' . $data->number . '金币' : $data->number),
                    $data->cash ? '+' . $data->cash . '元' : '',
                    $data->create_time,
                ];
            }
        }
        return $return;
    }


    /**
     * @return array
     */
    static function Autumn2018()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = MidAutumnLog::with('user:c_id,name')->where('is_prize', MidAutumnLog::PRIZE_YES)->where('is_real', 1);
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = [
                    $data->id,
                    $data->user->name,
                    MidAutumnLog::$TypeDisplay[$data->type],
                    $data->number,
                    date('Y-m-d H:i:s', $data->created_at)
                ];
            }
        }
        return $return;
    }


    /**
     * 健康咨询
     * @return array
     */
    static function HealthAdviceList()
    {
        $orderDir = $_POST['order'][0]['dir'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $id = request()->columns[0]['search']['value'];
        $user_name = request()->columns[1]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = HealthAdvice::select('id', 'title', 'user_name', 'cover', 'create_time', 'reading', 'praise', 'is_hot');
        $return['recordsTotal'] = $result->count();
        if ($id) {
            $result->where('id', $id);
        }
        if ($user_name) {
            $result->where('user_name', $user_name);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                if ($data->is_hot === HealthAdvice::HOT_YES) {
                    $set = "<button class='btn btn-success btn-hotoff' data-id='$data->id' >取消热门</button>";
                } else {
                    $set = "<button class='btn btn-success btn-hot' data-id='$data->id' >设置热门</button>";
                }
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $data->user_name,
                    $data->reading,
                    $data->praise,
                    HealthAdvice::$HotDisplay[$data->is_hot],
                    $data->create_time,
                    "<a class='btn' href='/healthAdvice/modify/$data->id' >修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>
                        $set
                        <a class='btn btn-info' href='/healthAdvice/repay/$data->id' >回复</a>"
                ];
            }
        }
        return $return;
    }

    /**
     * 健康咨询视频列表
     * @return array
     */
    static function healthAdviceVideoList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('health_advice_video')->select('id', 'title', 'path', 'pic_path');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", 'desc')->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $path = <<<TEXT
视频地址:$data->path ，
截图地址：$data->pic_path
TEXT;
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $path,
//                    "<video controls='' src='" . $data->path . "' width='200'></video>"
                ];
            }
        }
        return $return;
    }


    /**
     * @return array
     */
    static function healthAdviceTypeList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('health_advice_type')->select('id', 'type');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", 'desc')->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = [
                    $data->id,
                    $data->type,
                    "<button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>"
                ];
            }
        }
        return $return;
    }


    /**
     * @return array
     */
    static function OperationRecordLuckdrawList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $status = request()->columns[0]['search']['value'];
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = PrizeRecords::select('id', 'user_id', 'create_time', 'prize_name', 'status', 'phone', 'type', 'user_name', 'sheng', 'shi', 'xian', 'detail', 'check_content', 'express_name', 'express_order');
        $return['recordsTotal'] = $result->count();

        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = '';

                if ($data->status === PrizeRecords::STATUS_PENDING) {
                    //虚拟物品
                    if ($data->type === PrizeRecords::TYPE_CHARGE) {
                        $set = "<button class='btn btn-info btn-agree' data-id='$data->id' >通过</button>";
                    }
                    //实体
                    if ($data->type === PrizeRecords::TYPE_REAL) {
                        $set = "<button  class='btn btn-info'  onclick='agree(" . $data->id . ")' data-toggle='modal' data-target='#agree' >通过</button>";
                    }
                    $set .= "<button  class='btn btn-info'  onclick='refuse(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >拒绝</button>";
                }
                $user_name = DB::table('t_member')->where('c_id', $data->user_id)->value('name');
                $return['data'][] = [
                    $data->id,
                    $user_name,
                    $data->prize_name,
                    $data->phone,
                    PrizeRecords::$StatusDisplay[$data->status],
                    $data->check_content ? $data->check_content : $data->express_name . ":" . $data->express_order,
                    $data->create_time,
                    $set
                ];
            }
        }
        return $return;
    }

    /**
     * 游戏列表
     * @return array
     */
    static function GameList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        #数据
        $result = Game::select('id', 'name');
        $return['recordsTotal'] = $result->count();

        if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    "<a class='btn btn-info' href='/game/gameInfo/$data->id' >游戏详情</a>"
                ];
            }
        }
        return $return;
    }

    /**
     * 游戏状态列表
     * @return array
     */
    static function GameStatusList($game_id)
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        #数据
        $result = GameStatus::select('id', 'name')->where('game_id', $game_id);
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderBy('id')->skip($start)->take($pageNum)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    "<a class='btn btn-info' href='/game/status/info/$data->id' >状态详情</a>
                    <button class='btn btn-danger btn-status-del' data-id=$data->id >删除</button>"
                ];
            }
        }
        return $return;
    }

    /**
     * 游戏奖励列表
     * @param $game_id
     * @return array
     */
    static function GameCommodityList($game_id)
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        #数据
        $result = GameCommodity::select('id', 'name')->where('game_id', $game_id);
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderBy('id')->skip($start)->take($pageNum)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    "<a class='btn btn-info' href='/game/commodity/info/$data->id' >状态详情</a>
                     <button class='btn btn-danger btn-commodity-del' data-id=$data->id >删除</button>"
                ];
            }
        }
        return $return;
    }


    /**
     * 游戏奖品领取记录
     * @return array
     */
    static function GamePrizeList()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $status = request()->columns[0]['search']['value'];
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = GamePrizeLog::with('user:c_id,name')->with('game:id,name')->with('commodity:id,name');
        $return['recordsTotal'] = $result->count();

        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->orderByDesc('id')->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = '';
                if ($data->status === GamePrizeLog::STATUS_WAITING) {
                    $set = "<button  class='btn btn-info'  onclick='agree(" . $data->id . ")' data-toggle='modal' data-target='#agree' >通过</button>";
                    $set .= "<button  class='btn btn-info'  onclick='refuse(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >拒绝</button>";
                }
                $return['data'][] = [
                    $data->id,
                    $data->user->name,
                    $data->game->name,
                    $data->commodity->name,
                    $data->user_name,
                    $data->phone,
                    GamePrizeLog::$StatusDisplay[$data->status],
                    $data->check_content ? $data->check_content : $data->express_name . ":" . $data->express_order,
                    $data->create_time,
                    $set
                ];
            }
        }
        return $return;
    }

    /**
     * @return array
     */
    static function tasks()
    {
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $return['data'] = [];

        //数据
        $result = DB::table('day_tasks')->select('id', 'name', 'number', 'frequency', 'content', 'add_number')->where('id', '!=', 1);
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        // 显示数量
        $datas = $result->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button  class='btn btn-info'  onclick='edit(" . $data->id . ")' data-toggle='modal' data-target='#edit ' >编辑</button>";
                $return['data'][] = [
                    $data->name,
                    $data->number,
                    $data->frequency,
                    $data->content,
                    $data->add_number,
                    $set
                ];
            }
        }
        return $return;
    }


    /**
     * 健康档案列表
     * @return array
     */
    static function HealthRecordsList()
    {
        //排序
        $columns = [
            0 => 'id',
            4 => 'age',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $status = request('columns')[0]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = HealthRecords::select('id', 'user_uuid', 'age', 'name', 'relationship', 'sex', 'telephone', 'status')
            ->where('is_del', HealthRecords::DEL_OFF);
        $return['recordsTotal'] = $result->count();
        //条件筛选
        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    User::where('uuid', $data->user_uuid)->value('name'),
                    $data->name,
                    $data->sex,
                    $data->age,
                    $data->relationship,
                    $data->telephone,
                    HealthRecords::$StatusDisplay[$data->status],
                    "<a class='btn btn-info' href='/healthRecords/info/$data->id'>编辑</a>"
                );
            }
        }

        return $return;
    }

    /**
     * @param $healthAdvice_id
     * @return array
     */
    static function Repays($healthAdvice_id)
    {
        //排序
        $columns = [
            0 => 'id',
            4 => 'creat_time',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = HealthComment::select('id', 'user_name', 'user_head', 'comment', 'creat_time')->where('information_id', $healthAdvice_id);
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->user_name,
                    "<img src='$data->user_head' width='100px'>",
                    "<p class='comment'>$data->comment</p>",
                    $data->creat_time,
                );
            }
        }

        return $return;
    }

    /**
     * @return array
     */
    static function ApplyVip()
    {
        //排序
        $columns = [
            0 => 'id',
            2 => 'id_card',
            4 => 'contact_phone',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = BaseMerchantApplyMembers::select('id', 'merchant_name', 'id_card', 'contact_name', 'contact_phone', 'merchant_nature');
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->merchant_name,
                    $data->id_card,
                    $data->contact_name,
                    $data->contact_phone,
                    $data->merchant_nature,
                );
            }
        }

        return $return;
    }


    /**
     * @return array
     */
    static function ApplyTry()
    {
        //排序
        $columns = [
            0 => 'id',
            2 => 'id_card',
            3 => 'contact_phone',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = BaseUserApply::select('id', 'name', 'id_card', 'contact_phone', 'province', 'city', 'district', 'address_detail');
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->name,
                    $data->id_card,
                    $data->contact_phone,
                    $data->province . $data->city . $data->district . $data->address_detail,
                );
            }
        }

        return $return;
    }


    /**
     * @return array
     */
    static function BaseApplyVip()
    {
        //排序
        $columns = [
            0 => 'id',
            2 => 'id_card',
            3 => 'mobile',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('base_vip_apply')->select('id', 'name', 'id_card', 'mobile', 'create_time');
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->name,
                    $data->id_card,
                    $data->mobile,
                    $data->create_time
                );
            }
        }

        return $return;
    }


    /**
     * 跑步答题题库
     * @return array
     */
    static function RunGameItems()
    {
        //排序
        $columns = [
            0 => 'id',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = RunGameItems::select('id', 'title', 'created_at');
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->title,
                    date('Y-m-d H:i:s', $data->created_at)
                );
            }
        }

        return $return;
    }

    /**
     * 跑步答题游戏赛季
     * @return array
     */
    static function RunGameSeasons()
    {
        //排序
        $columns = [
            0 => 'id',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = RunGameSeason::select('id', 'title', 'start_at', 'end_at');
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->title,
                    date('Y-m-d H:i:s', $data->start_at),
                    date('Y-m-d H:i:s', $data->end_at),
                    "<button class='btn btn-info btn-del' data-id='$data->id'>删除</button>"
                );
            }
        }

        return $return;
    }

    /**
     * 跑步答题游戏奖励
     * @return array
     */
    static function SeasonsReward()
    {
        //排序
        $columns = [
            0 => 'id',
            2 => 'ranking',
            5 => 'start_at',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = RunGameReward::select('id', 'title', 'img', 'ranking', 'is_use', 'start_at');
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->title,
                    $data->ranking,
                    "<img src='$data->img' width='150px'>",
                    RunGameReward::$UseDisplay[$data->is_use],
                    date('Y-m-d H:i:s', $data->start_at),
                    $data->id && $data->start_at !== 0 ? "<button class='btn btn-info btn-del' data-id='$data->id'>删除</button>" : ""
                );
            }
        }

        return $return;
    }

    /**
     * 游戏奖励领取
     * @return array
     */
    static function RunGamePrice()
    {
        //排序
        $columns = [
            0 => 'id',
            6 => 'status',
            7 => 'created_at',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $id = request()->columns[0]['search']['value'];
        $status = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = RunGamePrize::with('user:c_id,name')->with('reward:id,title');
        $return['recordsTotal'] = $result->count();

        //过滤
        if ($id) {
            $result->where('id', $id);
        }
        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = '';
                if ($data->status === RunGamePrize::STATUS_SHIPPING) {
                    $set = "<button  class='btn btn-info'  onclick='send(" . $data->id . ")' data-toggle='modal' data-target='#send' >发货</button>";
                }
                $return['data'][] = array(
                    $data->id,
                    $data->user->name,
                    $data->reward->title,
                    $data->name,
                    $data->mobile,
                    $data->province . $data->city . $data->county . $data->address,
                    RunGamePrize::$StatusDisplay[$data->status],
                    date('Y-m-d H:i:s', $data->created_at),
                    $set
                );
            }
        }

        return $return;
    }


    /**
     * 游戏角色列表
     * @return array
     */
    static function RunGameRole()
    {
        //排序
        $columns = [
            0 => 'id',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = RunGameRole::select('id', 'path');
        $return['recordsTotal'] = $result->count();

        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    "<img src='$data->path' width='150px'>",
                    "<button  class='btn btn-info btn-del'  data-id = '$data->id' >删除</button>"
                );
            }
        }

        return $return;
    }


    /**
     * 游戏记录
     * @return array
     */
    static function RunGameLog()
    {
//排序
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $time = request()->columns[0]['search']['value'];
        $season_id = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = RunGameLogs::select('user_id', 'season_id', 'item_ids', 'start_at')->where('season_id', '!=', 0);
        $return['recordsTotal'] = $result->count();
        if ($time) {
            $result->whereBetween('start_at', date2Str($time));
        }
        if (is_numeric($season_id)) {
            $result->where('season_id', $season_id);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy('start_at', $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    User::where('c_id', $data->user_id)->value('name'),
                    RunGameSeason::where('id', $data->season_id)->value('title'),
                    count(explode(',', $data->item_ids)),
                    date('Y-m-d H:i:s', $data->start_at),
                );
            }
        }

        return $return;
    }


    /**
     * @return array
     */
    static function BehaviorLog()
    {
        //排序
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $time = request()->columns[0]['search']['value'];
        $sign = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = BehaviorLog::select('user_id', 'post_times', 'comment_times', 'create_time', 'del_post_times', 'sign');
        $times = '';
        $signs = '全部';
        $behavior_log = BehaviorLog::where('id', '>', 0);
        $return['recordsTotal'] = $result->count();
        if ($time) {
            $time = date2Date($time);
            $result->where('last_update_time', '>', $time[0])->where('last_update_time', '<', $time[1]);
            $behavior_log->where('last_update_time', '>', $time[0])->where('last_update_time', '<', $time[1]);
            $times = "$time[0] - $time[1]";
        }
        if (is_numeric($sign)) {
            $result->where('sign', $sign);
            $behavior_log->where('sign', $sign);
            $signs = BehaviorLog::$SignDisplay[$sign];
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy('create_time', $dir)->get();
        $return['data'][] = [
            '<p style="color:red">全部</p>',
            '<p style="color:red">' . $behavior_log->sum('post_times') . '</p>',
            '<p style="color:red">' . $behavior_log->sum('comment_times') . '</p>',
            '<p style="color:red">' . $behavior_log->sum('del_post_times') . '</p>',
            '<p style="color:red">' . $signs . '</p>',
            '<p style="color:red">' . $times . '</p>',
        ];
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    User::where('c_id', $data->user_id)->value('name'),
                    $data->post_times,
                    $data->comment_times,
                    $data->del_post_times,
                    BehaviorLog::$SignDisplay[$data->sign],
                    $data->create_time,
                );
            }
        }

        return $return;
    }

    /**
     * @return array
     */
    static function LoginLog()
    {
        //排序
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $time = request()->columns[0]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('login_log')->select(DB::raw(' count(id) as login_numner, create_time'))->groupBy('create_time');
        $return['recordsTotal'] = count($result->get());
        if ($time) {
            $time = date2Date($time);
            $result->where('last_login_time', '>', $time[0])->where('last_login_time', '<', $time[1]);
        }

        // 过滤后的总数量
        $return['recordsFiltered'] = count($result->get());
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy('create_time', $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->login_numner,
                    $data->create_time
                );
            }
        }

        return $return;
    }

    /**
     * @return array
     */
    static function RunGameRank()
    {
        //排序
        $columns = [
            0 => 'id',
            1 => 'season_id',
            2 => 'integral',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $time = request()->columns[0]['search']['value'];
        $season_id = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = RunGameRank::select('user_id', 'season_id', 'integral')->where('season_id', '!=', 0);
        $return['recordsTotal'] = $result->count();
        if ($time) {
            $result->whereBetween('created_at', date2Str($time));
        }
        if (is_numeric($season_id)) {
            $result->where('season_id', $season_id);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    User::where('c_id', $data->user_id)->value('name'),
                    RunGameSeason::where('id', $data->season_id)->value('title'),
                    $data->integral,
                );
            }
        }

        return $return;
    }


    /**
     * 超市列表
     * @return array
     */
    static function MarketList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $time = request()->columns[0]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = MarketList::select('id', 'title', 'mobile', 'remarks');
        $return['recordsTotal'] = $result->count();
        if (!$time) {
            $date = ['2019-01-01 00:00:00', '2029-01-01 00:00:00'];
        } else {
            $date = date2Date($time);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy('id', 'desc')->get();
        $user_union_ids = MarketRotaryUser::where('market_id', 0)->where('create_time', '>=', $date[0])->where('create_time', '<=', $date[1])->pluck('user_union_id')->toArray();
        $user_ids = User::whereIn('union_id', $user_union_ids)->pluck('c_id')->toArray();
        //下载人数
        $duwnload = DB::table('login_log')->whereIn('user_id', $user_ids)->groupBy('user_id')->getCountForPagination();

        $return['data'][] = [
            '分享',
            '分享',
            '分享',
            '分享',
            count($user_union_ids),
            $duwnload,
            '分享',
            '分享',
            '分享',
        ];
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                //招揽用户
                $user_union_ids = MarketRotaryUser::where('market_id', $data->id)->where('create_time', '>=', $date[0])->where('create_time', '<=', $date[1])->pluck('user_union_id')->toArray();
                $user_ids = User::whereIn('union_id', $user_union_ids)->pluck('c_id')->toArray();
                //下载人数
                $duwnload = DB::table('login_log')->whereIn('user_id', $user_ids)->groupBy('user_id')->getCountForPagination();
                $return['data'][] = [
                    $data->id,
                    Qrcode::size(200)->generate('https://wechatlt.jkbanlv.com/h5/web/wechat/rotateShop.html?id=' . $data->id),
                    Qrcode::size(200)->generate(url('/market/search/' . $data->id)),
                    $data->title,
                    count($user_union_ids),
                    $duwnload,
                    $data->mobile,
                    $data->remarks,
                    "<button  class='btn btn-info'  onclick='modify(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >修改</button>"
                ];
            }
        }

        return $return;
    }


    /**
     * VIP列表
     * @return array
     */
    static function StoreVipList()
    {
        //排序
        $columns = [
            0 => 'title',
            1 => 'weight',
            7 => 'timelimt',
            8 => 'docnum',
            9 => 'shownum',
            10 => 'coupon',
            11 => 'keeptime',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = Vip::select('id', 'weight', 'title', 'timelimt', 'circle', 'docnum', 'shownum', 'scanuser', 'coupon', 'qunsend', 'consulttype', 'keeptime', 'status');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->title,
                    $data->weight,
                    Vip::$CircleStatusDisplay[$data->circle],
                    Vip::$ScanuserDisplay[$data->scanuser],
                    Vip::$ConsultTypeDisplay[$data->consulttype],
                    Vip::$StatusDisplay[$data->status],
                    Vip::$QunsendDisplay[$data->qunsend],
                    $data->timelimt,
                    $data->docnum,
                    $data->shownum,
                    $data->coupon,
                    $data->keeptime,
                    "<button  class='btn btn-info'  onclick='modify(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >编辑</button>"
                );
            }
        }

        return $return;
    }


    /**
     * 商户提现列表
     * @return array
     */
    static function ShanghuWithdrawList()
    {
//排序
        $columns = [
            0 => 'id',
            7 => 'createtime',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $withdrawcode = request('columns')[0]['search']['value'];
        $status = request('columns')[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = JkblShanghuWithdraw::with('shanghu:id,store_name,alipay');
        $return['recordsTotal'] = $result->count();
        //条件筛选
        if ($withdrawcode) {
            $result->where('withdrawcode', $withdrawcode);
        }
        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();
//        dd($datas);
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = '';
                if ($data->shanghu) {
                    if ($data->status === JkblShanghuWithdraw::STATUS_WAITTING) {
                        $set = "<button class='btn btn-info btn-done' data-id='$data->id'>通过</button>
                        <button  class='btn btn-info'  onclick='refuse(" . $data->id . ")' data-toggle='modal' data-target='#refuse' >不通过</button>";
                    }
                    $return['data'][] = array(
                        $data->withdrawcode,
                        $data->shanghu->store_name,
                        $data->shanghu->alipay,
                        $data->money,
                        "<p class='status$data->id'>" . JkblShanghuWithdraw::$StatusDisplay[$data->status] . "</p>",
                        date('Y-m-d H:i:s', $data->createtime),
                        $set
                    );
                }
            }
        }

        return $return;
    }


    /**
     * 擅长领域
     * @return array
     */
    static function DoctorExpert()
    {
        //排序
        $columns = [
            0 => 'title',
            1 => 'display',
            2 => 'status',
            4 => 'createtime'
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';


        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DoctorExpert::select('id', 'display', 'title', 'createtime', 'status', 'bordercolor');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                if ($data->status === DoctorExpert::STATUS_OFF) {
                    $set = "<button class='btn btn-info btn-status' data-id='$data->id' >显示</button>";
                } else {
                    $set = "<button class='btn btn-info btn-status' data-id='$data->id' >隐藏</button>";
                }
                $set .= "<button class='btn btn-danger btn-del' data-id='$data->id'>删除</button>";
                $return['data'][] = [
                    $data->title,
                    $data->display,
                    DoctorExpert::$StatusDisplay[$data->status],
                    "<input class='form-control' type='color' value=$data->bordercolor id='example-color-input'>",
                    date('Y-m-d H:i:s', $data->createtime),
                    $set
                ];
            }
        }

        return $return;
    }

    /**
     * 医生类型
     * @return array
     */
    static function DoctorType()
    {
        //排序
        $columns = [
            0 => 'title',
            1 => 'display',
            2 => 'status',
            4 => 'createtime'
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';


        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DoctorType::select('id', 'display', 'title', 'createtime', 'status', 'needqualification');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                if ($data->status === DoctorType::STATUS_OFF) {
                    $set = "<button class='btn btn-info btn-status' data-id='$data->id' >显示</button>";
                } else {
                    $set = "<button class='btn btn-info btn-status' data-id='$data->id' >隐藏</button>";
                }
                if ($data->needqualification === DoctorType::QUAL_NO) {
                    $set .= "<button class='btn btn-primary btn-needqualification' data-id='$data->id' >需要资格证</button>";
                } else {
                    $set .= "<button class='btn btn-primary btn-needqualification' data-id='$data->id' >取消资格证</button>";
                }
                $set .= "<button class='btn btn-danger btn-del' data-id='$data->id'>删除</button>";
                $return['data'][] = [
                    $data->title,
                    $data->display,
                    DoctorType::$StatusDisplay[$data->status],
                    DoctorType::$QualDisplay[$data->needqualification],
                    date('Y-m-d H:i:s', $data->createtime),
                    $set
                ];
            }
        }

        return $return;
    }


    /**
     * 医生管理
     * @return array
     */
    static function DoctorList()
    {
        //排序
        $columns = [
            0 => 'id',
            1 => 'person_name',
            5 => 'age',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $person_name = request('columns')[0]['search']['value'];
        $status = request('columns')[1]['search']['value'];
        $type = request('columns')[2]['search']['value'];
        $shid = request('columns')[3]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        //为删除的商户ID
        $shids = ShopInfo::where('del', ShopInfo::DEL_OFF)->whereIn('status', [ShopInfo::STATUS_YES, ShopInfo::STATUS_NEW])->pluck('id')->toArray();
        // 过滤前数量
        $result = Doctor::select('id', 'shid', 'person_name', 'sex', 'age', 'type', 'avatar', 'status')
            ->where('del', Doctor::DEL_OFF)
            ->whereIn('shid', $shids);
        $return['recordsTotal'] = $result->count();
        //条件筛选
        if ($person_name) {
            $result->where('person_name', 'like', '%' . $person_name . '%');
        }
        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        if (is_numeric($type)) {
            $result->where('type', $type);
        }
        if (is_numeric($shid)) {
            $result->where('shid', $shid);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->person_name,
                    "<img src='$data->avatar' width='150px'>",
                    ShopInfo::where('id', $data->shid)->value('store_name'),
                    Doctor::$SexDisplay[$data->sex],
                    $data->age,
                    DoctorType::where('id', $data->type)->value('title'),
                    Doctor::$StatusDisplay[$data->status],
                    "<a class='btn btn-info' href='/doctor/info/$data->id'>编辑</a>
                    <button class='btn btn-del' data-id=$data->id>删除</button>"
                );
            }
        }

        return $return;
    }


    ######广告

    /**
     * 公司列表
     * @return array
     */
    static function AdCompaniesList()
    {
        //排序
        $columns = [
            0 => 'id',
            2 => 'ad_num',
            3 => 'ad_on_num',
            5 => 'created_at',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $company_name = request('columns')[0]['search']['value'];
        $status = request('columns')[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        //为删除的商户ID
        // 过滤前数量
        $result = AdCompanies::select('id', 'name', 'status', 'ad_num', 'ad_on_num', 'remarks', 'created_at');
        $return['recordsTotal'] = $result->count();
        //条件筛选
        if ($company_name) {
            $result->where('name', 'like', '%' . $company_name . '%');
        }
        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->name,
                    $data->ad_num,
                    $data->ad_on_num,
                    "<p class='del-$data->id'>" . AdCompanies::$StatusDisplay[$data->status] . "</p>",
                    $data->remarks,
                    date("Y-m-d H:i:s", $data->created_at),
                    $data->status === AdCompanies::STATUS_ON ? "<button class='btn btn-del' data-id=$data->id>删除</button>" : ''
                );
            }
        }

        return $return;
    }

    /**
     * 广告列表
     * @return array
     */
   /* static function AdList()
    {
        //排序
        $columns = [
            0 => 'id',
            6 => 'design_cost',
            7 => 'time_cost',
            8 => 'click_times',
            11 => 'created_at',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $title = request('columns')[0]['search']['value'];
        $status = request('columns')[1]['search']['value'];
        $company_id = request('columns')[2]['search']['value'];
        $time = request('columns')[3]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = AdList::with('adCompany:id,name');
        $return['recordsTotal'] = $result->count();
        //条件筛选
        if ($title) {
            $result->where('title', 'like', '%' . $title . '%');
        }
        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        if (is_numeric($company_id)) {
            $result->where('company_id', $company_id);
        }
        if ($time) {
            $result->whereBetween('created_at', date2Str($time));
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->title,
                    $data->adCompany->name,
                    AdList::$TypeDisplay[$data->type],
                    "<img src='$data->image' width='150px'/>",
                    "<a href='http://$data->url_link'>" . $data->url_link . "</a>",
                    $data->design_cost,
                    $data->time_cost,
//                    $data->click_times,
                    $data->explain,
                    "<p class='del-$data->id'>" . AdList::$StatusDisplay[$data->status] . "</p>",
                    date("Y-m-d H:i:s", $data->created_at),
                    $data->status === AdList::STATUS_ON ?
                        "<button  class='btn btn-info'  onclick='edit(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >编辑</button>
                            <button class='btn btn-del' data-id=$data->id>删除</button>" : ''
                );
            }
        }

        return $return;
    }*/

    /**
     * 图片列表
     * @return array
     */
    static function BannerPicList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('banner_pic')->select('id', 'title', 'path');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", 'desc')->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = [
                    $data->id,
                    $data->title,
                    $data->path,
                ];
            }
        }
        return $return;
    }
	
	
    /**
     * 资讯分类列表
     * @return array
     */
    static function FenleiList()
    {
        $orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $shop_name = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_column_dic')->select('id', 'column_name', 'create_time','is_del')->where('is_del', Zixun::DEL_ON);
        $return['recordsTotal'] = $result->count();
        if ($shop_name) {
            $result->where('column_name', 'like', '%' . $shop_name . '%');
        }  
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'create_time';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<a class='btn btn-info' data-id='$data->id' href='/zixun/fenleiModify/$data->id'>修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>
						<button class='btn btn-success btn-shauxin' data-id='$data->id' >刷新</button>";
                $return['data'][] = [
                    $data->id,
                    $data->column_name,
                    $data->create_time,
                    $set
                ];
            }
        }
        return $return;
    }

    /**
     * 资讯评论列表
     * @return array
     */
    static function Zxreplay($id)
    {
        $orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
		
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $content = request()->columns[0]['search']['value'];
		$del = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_article_comment')->select('id', 'user_id','user_name','content', 'create_time','light_num','is_del')->where('article_id', $id);
        $return['recordsTotal'] = $result->count();
        if ($content) {
            $result->where('content', 'like', '%' . $content . '%');
        }  
		if ($del!='') {
            $result->where('is_del', $del);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'id';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				//if(mb_strlen($data->content)>11){
				//	$content = mb_substr($data->content,0,11,'utf-8').'...';
				//}else{
					$content = $data->content;
				//}
                $set = "<a class='btn btn-info' data-id='$data->id' href='/zixun/zxhuifu/$data->id'>回复</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>";
				$uname = DB::table('t_member')->where('c_id', $data->user_id)->value('name');
                $return['data'][] = [
                    $data->id,
                    $uname,
					$content,
                    $data->create_time,
					$data->light_num,
                    $set
                ];
            }
        }
        return $return;
    }

    /**
     * 资讯评论回复列表
     * @return array
     */
    static function Zxcomentreplay($id)
    {
        $orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
		
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $content = request()->columns[0]['search']['value'];
		$del = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_article_comment_reply')->select('id', 'user_name','content', 'create_time','light_num','is_del')->where('comment_id', $id);
        $return['recordsTotal'] = $result->count();
        if ($content) {
            $result->where('content', 'like', '%' . $content . '%');
        }  
		if ($del!='') {
            $result->where('is_del', $del);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'id';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				if(mb_strlen($data->content)>11){
					$content = mb_substr($data->content,0,11,'utf-8').'...';
				}else{
					$content = $data->content;
				}
                $set = "<button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>";
                $return['data'][] = [
                    $data->id,
                    $data->user_name,
					$content,
                    $data->create_time,
					$data->light_num,
                    $set
                ];
            }
        }
        return $return;
    }

    /**
     * 圈子分类列表
     * @return array
     */
    static function QfenleiList()
    {

        $orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $shop_name = request()->columns[0]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_circle_dic')->select('id', 'name', 'pic_path','create_time','is_del','view_num','follow_num');
        $return['recordsTotal'] = $result->count();
        if ($shop_name) {
            $result->where('name', 'like', '%' . $shop_name . '%');
        }  
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'create_time';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<a class='btn btn-info' data-id='$data->id' href='/quanzi/fenleiModify/$data->id'>修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>
						<button class='btn btn-success btn-shauxin' data-id='$data->id' >刷新</button>";
                $return['data'][] = [
                    $data->id,
                    $data->name,
					 "<img src='$data->pic_path' width='50px'/> ",
					$data->view_num,
					$data->follow_num,
                    $data->create_time,
					Qfenglei::$DelDisplay[$data->is_del],
                    $set
                ];
            }
        }
        return $return;
    }	
	
	    /**
     * 圈子列表
     * @return array
     */
    static function QzsList()
    {

        $orderDir = $_POST['order'][0]['dir'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $id = request()->columns[0]['search']['value'];
        $content = request()->columns[1]['search']['value'];
        $top = request()->columns[2]['search']['value'];//置顶
        $excell = request()->columns[3]['search']['value'];//加精
		$push_flag = request()->columns[4]['search']['value'];//发布状态

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = Carticle::select('id', 'title', 'content','user_id', 'push_time','push_flag','circle_id', 'create_time', 'is_del', 'is_excellent','comment_num', 'light_num','is_top');
        $return['recordsTotal'] = $result->count();
        if ($id) {
            $result->where('id', $id);
        }
        if ($content) {
            $result->where('content', 'like' ,'%'.$content.'%');
        }
        if ($top!='') {
            $result->where('is_top', $top);
        }
        if ($excell!='') {
            $result->where('is_excellent', $excell);
        }
        if ($push_flag!='') {
            $result->where('push_flag', $push_flag);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				if(mb_strlen($data->content)>8){
					$title = mb_substr($data->content,0,8,'utf-8')."...";
				}else{
					$title = $data->content;
				}
                if ($data->is_del === Carticle::DEL_NO && $data->push_time=='') {
					$set = '';
                } elseif($data->push_time && strtotime($data->push_time) >= time()){
					$set = "<button class='btn btn-danger btn-chexiao' data-id='$data->id' >撤销</button>"; 
				}else{
                    $set = "<button  class='btn btn-danger'  onclick='del(" . $data->id . ")' data-toggle='modal' data-target='#btn-del' >删除</button>";
                }

                if ($data->is_excellent === Carticle::ISEXC_YES) {
					$set .= " <span class='btn-hot$data->id'><button class='btn btn-success btn-hotoff' data-id='$data->id' >取消加精</button></span>";
                } else {
					 $set .= "<button class='btn btn-success btn-jj' data-id='$data->id' >加精</button>";
                }
                if ($data->is_top === Carticle::TOP_YES) {
					$set .= " <span class='btn-zhiding$data->id'><button class='btn btn-success btn-topoff' data-id='$data->id' >取消置顶</button></span>";
                } else {
                    $set .= " <button  class='btn btn-info'  onclick='zhiding(" . $data->id . ")' data-toggle='modal' data-target='#btn-zhiding' >置顶</button>";
                }
				if(DB::table('t_member')->select('name')->where('c_id', $data->user_id)->first()){
					$udata = DB::table('t_member')->select('name')->where('c_id', $data->user_id)->first();
					$names = $udata->name;
				}else{
					$names = '';
				}
				
				
				if(!DB::table('kl_circle_dic')->select('name')->where('id', $data->circle_id)->first()){
					$lanmname = '没名';
					//echo $data->circle_id.'<p>';
				}else{
					$lanmu = DB::table('kl_circle_dic')->select('name')->where('id', $data->circle_id)->first();
					$lanmname = $lanmu->name;
				}
				//if(!Carticle::$IsexcDisplay[$data->is_excellent]){
				//	$jing = '未知';
				//}else{
					$jing = Carticle::$IsexcDisplay[$data->is_excellent]?Carticle::$IsexcDisplay[$data->is_excellent]:'未知';
				//}
					$return['data'][] = [
						$data->id,
						$lanmname,
						$names,
						$title,
						$data->light_num,
						$data->comment_num,
						$jing,
						Carticle::$TopDisplay[$data->is_top],
						Carticle::$DelDisplay[$data->is_del],
						$data->create_time,
						"<a class='btn' href='/quanzi/zxlistModify/$data->id' >修改</a>
							$set
							<a class='btn btn-info' href='/quanzi/repay/$data->id' >评论</a>"
					];
            }
        }
        return $return;
    }
	
	//圈子图片
	static function Czpiclist($id){
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Circlepic::select('id','pic_path', 'is_del','create_time')->where('circle_article_id',$id);
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/quanzi/listpicModify/$data->id' >修改</a>";
                $pic = "<img src='$data->pic_path' width='50px'/> ";
                $return['data'][] = [
                    $data->id,
                    $pic,
					Circlepic::$DelDisplay[$data->is_del],
                    $set
                ];
            }
        }
        return $return;	
	}
	
    /**
     * 圈子评论列表
     * @return array
     */
    static function Czreplay($id)
    {
        $orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
		
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $content = request()->columns[0]['search']['value'];
		$del = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_circle_comment')->select('id', 'user_id','user_name','user_avatr','content', 'create_time','light_num','is_del')->where('circle_article_id', $id);
        $return['recordsTotal'] = $result->count();
        if ($content) {
            $result->where('content', 'like', '%' . $content . '%');
        }  
		if ($del!='') {
            $result->where('is_del', $del);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'id';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				//if(mb_strlen($data->content)>11){
				//	$content = mb_substr($data->content,0,11,'utf-8').'...';
				//}else{
					$content = $data->content;
				//}
                $set = "<a class='btn btn-info' data-id='$data->id' href='/quanzi/zxhuifu/$data->id'>回复</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>";
						$pic = "<img src='$data->user_avatr' width='50px'/> ";
				$uname = DB::table('t_member')->where('c_id', $data->user_id)->value('name');
                $return['data'][] = [
                    $data->id,
                    $uname,
					$pic,
					$content,
                    $data->create_time,
					$data->light_num,
                    $set
                ];
            }
        }
        return $return;
    }
	
    /**
     * 圈子评论回复列表
     * @return array
     */
    static function Czcomentreplay($id)
    {
        $orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
		
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $content = request()->columns[0]['search']['value'];
		$del = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_circle_reply')->select('id', 'user_name','content', 'create_time','light_num','is_del')->where('comment_id', $id);
        $return['recordsTotal'] = $result->count();
        if ($content) {
            $result->where('content', 'like', '%' . $content . '%');
        }  
		if ($del!='') {
            $result->where('is_del', $del);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'id';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				if(mb_strlen($data->content)>11){
					$content = mb_substr($data->content,0,11,'utf-8').'...';
				}else{
					$content = $data->content;
				}
                $set = "<button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>";
                $return['data'][] = [
                    $data->id,
                    $data->user_name,
					$content,
                    $data->create_time,
					$data->light_num,
                    $set
                ];
            }
        }
        return $return;
    }
	
    /**
     * 咨询列表
     * @return array
     */
    static function ZxsList()
    {
        $orderDir = $_POST['order'][0]['dir'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $id = request()->columns[0]['search']['value'];
        $health_num_name = request()->columns[1]['search']['value'];
		$push_flag = request()->columns[2]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = ZxLists::select('id', 'title', 'health_num_name', 'view_num', 'push_time','push_flag','create_time', 'is_del', 'comment_num', 'light_num','column_id','hot');
        $return['recordsTotal'] = $result->count();
        if ($id) {
            $result->where('id', $id);
        }
        if ($health_num_name) {
            $result->where('health_num_name', $health_num_name);
        }
		
        if ($push_flag!='') {
            $result->where('push_flag', $push_flag);
        }
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : 10;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				if(DB::table('kl_column_dic')->select('column_name')->where('id', $data->column_id)->first()){
					if(mb_strlen($data->title)>11){
						$title = mb_substr($data->title,0,11,'utf-8').'...';
					}else{
						$title = $data->title;
					}
					if ($data->hot === ZxLists::HOT_YES) {
						$set = "<button class='btn btn-success btn-hotoff' data-id='$data->id' >取消热门</button>";
					} else {
						$set = "<button class='btn btn-success btn-hot' data-id='$data->id' >设置热门</button>";
					}
					if ($data->is_del === ZxLists::DEL_NO && $data->push_time=='') {
						$chedel = '';
					}elseif($data->push_time && strtotime($data->push_time) >= time()){
						$chedel = "<button class='btn btn-danger btn-chexiao' data-id='$data->id' >撤销</button>";
					}else{
						$chedel = "<button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>";
					}
					$leibie = DB::table('kl_column_dic')->select('column_name')->where('id', $data->column_id)->first();
					$return['data'][] = [
						$data->id,
						$leibie->column_name,
						$title,
						$data->health_num_name,
						$data->view_num,
						$data->light_num,
						$data->comment_num,
						ZxLists::$HotDisplay[$data->hot],
						ZxLists::$DelDisplay[$data->is_del],
						$data->create_time,
						"<a class='btn' href='/zixun/zxlistModify/$data->id' >修改</a>
							$chedel
							$set
							<a class='btn btn-info' href='/zixun/repay/$data->id' >评论</a>"
					];
				}else{
					DB::table('kl_article')->where('id', $data->id)->delete();
				}
			}
        }
        return $return;
    }
	
	//资讯banner
	static function BannerzxList(){
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Zxbanner::select('id', 'purl', 'link','type', 'sort');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/zixun/bannerModify/$data->id' >修改</a>";
                $pic = "<img src='$data->purl' width='200px'/> ";
                $return['data'][] = [
                    $data->id,
                    $pic,
					$data->link,
                    !empty($data->type)?Zxbanner::$ZxtypeDisplay[$data->type]:'',
                    $data->sort,
                    $set
                ];
            }
        }
        return $return;	
	}
	//资讯工具
	static function toolzxList(){
		$orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $del = request()->columns[1]['search']['value'];
        $homepage = request()->columns[2]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_function_dic')->select('id', 'name', 'pic','url','is_del','is_homepage','create_time');
        $return['recordsTotal'] = $result->count();
        if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }  
		if($del!=''){
			$result->where('is_del', $del);
		}
		
		if($homepage!=''){
			$result->where('is_homepage', $homepage);
		}
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'create_time';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<a class='btn btn-info' data-id='$data->id' href='/zixun/toolModify/$data->id'>修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>
						<button class='btn btn-success btn-shauxin' data-id='$data->id' >刷新</button>";
				$pic = "<img src='$data->pic' width='50px'/> ";
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    $pic,
					$data->url,
					Tool::$ShowDisplay[$data->is_homepage],
					Tool::$DelDisplay[$data->is_del],
					$data->create_time,
                    $set
                ];
            }
        }
        return $return;
	}
	
	//资讯列表
	static function ZxList(){
		$orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $del = request()->columns[1]['search']['value'];
        $homepage = request()->columns[2]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_function_dic')->select('id', 'name', 'pic','url','is_del','is_homepage','create_time');
        $return['recordsTotal'] = $result->count();
        if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }  
		if($del!=''){
			$result->where('is_del', $del);
		}
		
		if($homepage!=''){
			$result->where('is_homepage', $homepage);
		}
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'id';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<a class='btn btn-info' data-id='$data->id' href='/zixun/toolModify/$data->id'>修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>";
				$pic = "<img src='$data->pic' width='50px'/> ";
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    $pic,
					$data->url,
					Tool::$ShowDisplay[$data->is_homepage],
					Tool::$DelDisplay[$data->is_del],
					$data->create_time,
                    $set
                ];
            }
        }
        return $return;		
	}
	
	//专题分类
	static function ZtfenleiList(){
		$orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $del = request()->columns[1]['search']['value'];
        $homepage = request()->columns[2]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_tag_dic')->select('id', 'name', 'pic','is_del','is_homepage','remark','create_time');
        $return['recordsTotal'] = $result->count();
        if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }  
		if($del!=''){
			$result->where('is_del', $del);
		}
		
		if($homepage!=''){
			$result->where('is_homepage', $homepage);
		}
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'create_time';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $set = "<a class='btn btn-info' data-id='$data->id' href='/zixun/ztfenleiModify/$data->id'>修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>
						<button class='btn btn-success btn-shauxin' data-id='$data->id' >刷新</button>";
				$pic = "<img src='$data->pic' width='50px'/> ";
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    $pic,
					$data->create_time,
					Ztfenlei::$ShowDisplay[$data->is_homepage],
					Ztfenlei::$DelDisplay[$data->is_del],
                    $set
                ];
            }
        }
        return $return;
	}
	
	//专题列表
	static function ZtList(){
		$orderDir = $_POST['order'][0]['dir'];
        $orderColumn = $_POST['order'][0]['column'];
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $del = request()->columns[1]['search']['value'];
		$fenlei = request()->columns[2]['search']['value'];

        # 每页显示数量
        $pageNum = request('length', 10);

        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_tag_kind_dic')->select('id', 'tag_id','name', 'pic_path','is_del','create_time');
        $return['recordsTotal'] = $result->count();
        if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }  
		if($del!=''){
			$result->where('is_del', $del);
		}
		
		if($fenlei!=''){
			$result->where('tag_id', $fenlei);
		}
		
        $dir = $orderDir ? $orderDir : 'desc';
        // 过滤后的总数量 
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum; 
        $order = 'create_time';
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($order, $dir)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				$leibie = DB::table('kl_tag_dic')->select('name')->where('id', $data->tag_id)->first();
                $set = "<a class='btn btn-info' href='/zixun/listBanner/$data->id'>轮播</a>
						<a class='btn btn-info' href='/zixun/artlist/$data->id'>文章列表</a>
						<a class='btn btn-info' href='/zixun/arcirtlist/$data->id'>圈子文章列表</a>
						<a class='btn btn-info' data-id='$data->id' href='/zixun/ztlistModify/$data->id'>修改</a>
                        <button class='btn btn-danger btn-del' data-id='$data->id' >删除</button>
						<button class='btn btn-success btn-shauxin' data-id='$data->id' >刷新</button>";
				$pic = "<img src='$data->pic_path' width='50px'/> ";
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    $pic,
					$leibie->name,
					Ztlist::$DelDisplay[$data->is_del],
					$data->create_time,
                    $set
                ];
            }
        }
        return $return;
	}
	
	//资讯banner
	static function ZtfenleiBanner($id){
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Ztbanner::select('id', 'kind_id','pic_url', 'link','is_del','type','link_id', 'is_jump')->where('kind_id',$id);
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				//$leibie = DB::table('kl_tag_kind_dic')->select('name')->where('id', $data->kind_id)->first();
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/zixun/listbannerModify/$data->id' >修改</a>";
                $pic = "<img src='$data->pic_url' width='50px'/> ";
                $return['data'][] = [
                    $data->id,
                    $pic,
					$data->link,
					//$leibie->name,
                    !empty($data->type)?Ztbanner::$TypeDisplay[$data->type]:'',
					Ztbanner::$DelDisplay[$data->is_del],
                    $set
                ];
            }
        }
        return $return;	
	}
	
	//资讯专题底部文章
	static function ZtartcleList($id){
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Ztarticle::select('id', 'kind_id','article_id')->where('kind_id',$id);
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				$article = DB::table('kl_article')->select('title')->where('id', $data->article_id)->first();
                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/zixun/artModify/$data->id' >修改</a>";
                $return['data'][] = [
                    $data->id,
					$article->title,
                    $set
                ];
            }
        }
        return $return;	
	}
	
	//资讯专题底部圈子文章
	static function ZtcarticleList($id){
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        //每页显示数量
        $pageNum = request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = Ztcirarticle::select('id', 'kind_id','circle_article_id')->where('kind_id',$id);
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				$article = DB::table('kl_circle_article')->select('content')->where('id', $data->circle_article_id)->first();

                $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/zixun/artcirtModify/$data->id' >修改</a>";
                $return['data'][] = [
                    $data->id,
					mb_substr($article->content,0,10,'UTF-8'),
                    $set
                ];
            }
        }
        return $return;	
	}
	
	/**
     * 健康号列表
     * @return array
     */
    static function JkList()
    {
        $columns = [
            0 => 'id',
        ];
        $return = [];
        //1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $is_del = request()->columns[2]['search']['value'];
        $time = request()->columns[4]['search']['value'];
        $pageNum = request()->columns[5]['search']['value'];
        $column = request()->order[0]['column'];
        $dir = request()->order[0]['dir'];
        //每页显示数量
        $pageNum = $pageNum ? $pageNum : 10;//request('length', 10);
        //页码
        $start = request('start', 0);

        $return['data'] = [];

        //数据
        $result = HealthyNum::select('id', 'name', 'pic_path','create_time','status','is_del','type','follow_num');
        $return['recordsTotal'] = $result->count();

        if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }
        if ($is_del) {
            $result->where('is_del', $is_del);
        }

        if ($time) {
            $time = date2Date($time);
            $result->where('create_time', '>', $time[0])->where('create_time', '<', $time[1]);
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        //排序
        if (in_array($column, array_keys($columns))) {
            $result->orderBy($columns[$column], $dir);
        }
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                  if ($data->is_del === HealthyNum::DEL_ON) {
                    $del = "已删除";
                } else {
                    $del = "未删除";
                }              
                 $set = "<button class='btn btn-info btn-del' data-id='$data->id' >删除</button>
                        <a class='btn btn-success' href='/jiankang/jkModify/$data->id' >修改</a>";
                $return['data'][] = [
                    $data->id,
                    $data->name,
                    "<img src='" . $data->pic_path . "'width='70px' class='img-responsive' />",
                    $data->create_time,
					$data->follow_num,
                    $del,
					$set
                ];
            }
        }
        return $return;
    }
	
    /**
     * 广告列表
     * @return array
     */
    static function AdList()
    {
        //排序
        $columns = [
            0 => 'id',
            6 => 'design_cost',
            7 => 'time_cost',
            8 => 'click_times',
            11 => 'created_at',
        ];
        $column = request()->order[0]['column'];
        if (!array_key_exists($column, $columns)) {
            $orderColumn = 'id';
        } else {
            $orderColumn = $columns[$column];
        }
        $orderDir = request()->order[0]['dir'];
        $dir = $orderDir ? $orderDir : 'desc';

        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $title = request('columns')[0]['search']['value'];
        $status = request('columns')[1]['search']['value'];
        $company_id = request('columns')[2]['search']['value'];
        $time = request('columns')[3]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = AdList::with('adCompany:id,name');
        $return['recordsTotal'] = $result->count();
        //条件筛选
        if ($title) {
            $result->where('title', 'like', '%' . $title . '%');
        }
        if (is_numeric($status)) {
            $result->where('status', $status);
        }
        if (is_numeric($company_id)) {
            $result->where('company_id', $company_id);
        }
        if ($time) {
            $result->whereBetween('created_at', date2Str($time));
        }
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy($orderColumn, $dir)->get();

        if (count($datas) > 0) {
            foreach ($datas as $data) {
                $return['data'][] = array(
                    $data->id,
                    $data->title,
                    $data->adCompany->name,
                    AdList::$TypeDisplay[$data->type],
                    "<img src='$data->image' width='150px'/>",
                    "<a href='http://$data->url_link'>" . $data->url_link . "</a>",
                    $data->design_cost,
                    $data->time_cost,
//                    $data->click_times,
                    $data->explain,
                    "<p class='del-$data->id'>" . AdList::$StatusDisplay[$data->status] . "</p>",
                    date("Y-m-d H:i:s", $data->created_at),
                    $data->status === AdList::STATUS_ON ?
                        "<button  class='btn btn-info'  onclick='edit(" . $data->id . ")' data-toggle='modal' data-target='#exampleModal' >编辑</button>
                            <button class='btn btn-del' data-id=$data->id>删除</button>" : ''
                );
            }
        }

        return $return;
    }
	
    /**
     * 游戏图片列表
     * @return array
     */
    static function Gmpiclist()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));

        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('gave_pic')->select('id', 'path');
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", 'desc')->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
				 $avatar = $data->path;
                $pic = "<img src='$avatar' width='80px'/> ";
                $return['data'][] = [
                    $data->id,
                    $pic,
                    $data->path,
					"<button class='btn btn-del' data-id=$data->id>删除</button>"
                ];
            }
        }
        return $return;
    }
	
   /**
     * 打卡列表
     * @return array
     */
    static function peizhiList()
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $del = request()->columns[1]['search']['value'];
        $show = request()->columns[2]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_punch_match_config')->select('id', 'day_num','is_del','name','gold_num','create_time','status','pic_path');
		if ($name) {
            $result->where('name', 'like', '%' . $name . '%');
        }  
		if($del!=''){
			$result->where('is_del', $del);
		}
		
		if($show!=''){
			$result->where('status', $show);
		}
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
		
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", 'desc')->get();
        if (count($datas) > 0) {
            foreach ($datas as $data) {
                /*if ($data->status === Cpeizhi::STATUS_NO) {
                    $set = "<button class='btn btn-info status-on' data-id='$data->id' style='margin-right: 5px;'>开启</button>";
                } else {
                    $set = "<button class='btn btn-info status-off' data-id='$data->id' style='margin-right: 5px;'>关闭</button>";
                }*/
				$set="<a class='btn btn-info'  style='margin-right: 5px;' href='/punch/peizhiModify/$data->id'>编辑</a><button class='btn btn-del btn-danger' data-id=$data->id>删除</button>";
				if($data->pic_path){
					$pic = "<img src='$data->pic_path' width='40px'>";
				}else{
					$pic = "";
				}
				$return['data'][] = [
                    $data->id,
					$data->name,
					$pic,
                    $data->day_num,
					$data->gold_num,
					Cpeizhi::$DelDisplay[$data->is_del],				
                    $data->create_time,
					$set
                ];
            }
        }
        return $return;
    }
	
    /**
     * 记录列表
     * @return array
     */
    static function recodeList($id)
    {
        $return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $status = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_punch_match_sign')->select('id', 'user_id','create_time','is_del','give_gold_num','get_gold_num','status')->where('match_id',$id);
		if ($name) {
			$id = User::where('name',$name)->where('sign',1)->value('c_id');
            $result->where('user_id', $id);
        }
		
		if($status!=''){
			$result->where('status', $status);
		}
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
		
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", 'desc')->get();
        if (count($datas) > 0) {
			
            foreach ($datas as $data) {
				
                $return['data'][] = [
                    $data->id,
					User::where('c_id', $data->user_id)->where('sign', '1')->value('name'),
					$data->give_gold_num,
					$data->get_gold_num,
					MatchSign::$DelDisplay[$data->is_del],
					MatchSign::$STATUS[$data->status],					
                    $data->create_time
                ];
            }
        }
        return $return;
    }
	
	
	
    /**
     * 记录统计列表
     * @return array
     */
    static function tongjiList()
    {
		$return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        $del = request()->columns[1]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_punch_match_record')->select('id','config_id','number','gold_num','create_time','is_del','start_time','end_time');
		if ($name) {
			$id = Cpeizhi::where('name', $name)->value('id');
            $result->where('config_id', $id);
        }	
		if($del!=''){
			$result->where('is_del', $del);
		}		
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
		
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("id", 'desc')->get();
        if (count($datas) > 0) {
			
            foreach ($datas as $data) {
				$wancheng = DB::table('kl_punch_match_sign')->where('match_id',$data->id)->where('status',1)->count();//已完成
				$canyu = DB::table('kl_punch_match_sign')->where('match_id',$data->id)->where('status',2)->count();//正参与
				$weiwancheng = DB::table('kl_punch_match_sign')->where('match_id',$data->id)->where('status',0)->count();//未完成

                $return['data'][] = [
                    Cpeizhi::where('id', $data->config_id)->value('name'),
					$data->number,
					$wancheng,
					$canyu,
					$weiwancheng,
					$data->gold_num,
					$data->create_time,
					$data->start_time,
					$data->end_time,
					MatchRecord::$DelDisplay[$data->is_del],
					"<a class='btn btn-info'  style='margin-right: 5px;' href='/punch/recode/$data->id'>详情</a>"
                ];
            }
        }
        return $return;
    }
	
	//记录总合统计列表
	static function hetongji(){
		$return = [];
        // 1.获取参数
        $return['draw'] = intval(request('draw', 1));
        $name = request()->columns[0]['search']['value'];
        # 每页显示数量
        $pageNum = request('length', 10);
        # 页码
        $start = request('start', 0);
        $return['data'] = [];
        // 2.筛选数据
        // 过滤前数量
        $result = DB::table('kl_punch_match_sign')->select(DB::raw('count(id) as cshu,sum(give_gold_num) as touru,sum(get_gold_num) as dedao,user_id'))->groupBy('user_id');
		if ($name) {
			$id = User::where('name', $name)->where('sign', 1)->value('c_id');
            $result->where('user_id', $id);
        }
		$result->where('status',1)->where('is_del',1);
		
        $return['recordsTotal'] = $result->count();
        // 过滤后的总数量
        $return['recordsFiltered'] = $result->count();
        $pageNum = $pageNum < 0 ? $return['recordsFiltered'] : $pageNum;
		
        // 显示数量
        $datas = $result->skip($start)->take($pageNum)->orderBy("user_id", 'desc')->get();
        if (count($datas) > 0) {
			
            foreach ($datas as $data) {
				
                $return['data'][] = [
                    User::where('c_id', $data->user_id)->where('sign', 1)->value('name'),
					$data->touru,
					$data->dedao,
					$data->cshu
                ];
            }
        }
        return $return;
	}
	
}



